package com.fingard.dsp.bank.directbank.bfb01;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import org.apache.commons.codec.binary.Base64;

import com.fingard.constant.Format;
import com.fingard.dsp.bank.directConfig.ActSetItem;
import com.fingard.dsp.bank.directbank.DirectHelper;
import com.fingard.dsp.bank.directbank.FailCode;
import com.fingard.dsp.bank.directbank.PaymentState;
import com.fingard.dsp.bank.directbank.bankInterface.IBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.ReqQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.RetAtsQryBatPayRec;
import com.fingard.dsp.bank.reqrespobj.batpayrec.detail.RetAtsBatPayRecDetail;
import com.fingard.io.FileHelper;
import com.fingard.net.ConnState;
import com.fingard.text.StringHelper;
import com.fingard.util.DEHelper;

import sun.misc.BASE64Decoder;

public class BFB01BatPayRec extends BFB01Base implements IBatPayRec {

    // 1988
    public RetAtsBatPayRec d_1988_BatPay(ReqBatPayRec p_req1988) throws Exception {
        return d_BatPayRec(p_req1988);
    }

    // 9188
    public RetAtsBatPayRec d_9188_BatPay(ReqBatPayRec p_req9188) throws Exception {
        return d_BatPayRec(p_req9188);
    }

    // 批量代收和批量代付提交
    public RetAtsBatPayRec d_BatPayRec(ReqBatPayRec p_reqBat) throws Exception {
        // 返回ATS的对象
        RetAtsBatPayRec retAts = new RetAtsBatPayRec(p_reqBat.reqHeader);
        try {
            // 取第三方商户
            ActSetItem actItem = getBankConfig().getActSetItem(p_reqBat.ownAct, "");
            if (actItem == null || !FileHelper.existFile(actItem.ownKeyStorePath)) {
                retAts.respCode = "0";
                if (actItem == null) {
                    retAts.respInfo = "未找到账号" + p_reqBat.ownAct + "的批量商户配置节点";
                } else {
                    retAts.respInfo = "账号" + p_reqBat.ownAct + "的证书文件不存在";
                }
                retAts.reqSeqID = p_reqBat.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = FailCode.E9981;
                retAts.writeRetToATS();
                return retAts;
            }
            HashMap<String, String> sendMap = new HashMap<String, String>();
            sendMap.put("version", "1.0");
            sendMap.put("transCode", "batchTrans");// 交易代码
            String transType = "";
			/*01：代收自银行卡
02：代付到银行卡
03：代收自账户（暂不支持）
04：代付到账户
05：代发工资到账户
06：代发工资到银行卡
07：实时代付到银行卡
*/
            if (p_reqBat.reqHeader.transType.equals("1988")) {
                if (p_reqBat.reqHeader.commandCode.equals("198801")) {
                    transType = "02";
                } else if (p_reqBat.reqHeader.commandCode.equals("198802")) {
                    transType = "04";
                } else if (p_reqBat.reqHeader.commandCode.equals("198803")) {
                    transType = "05";
                } else if (p_reqBat.reqHeader.commandCode.equals("198804")) {
                    transType = "06";
                } else if (p_reqBat.reqHeader.commandCode.equals("198805")) {
                    transType = "07";
                }
            } else if (p_reqBat.reqHeader.transType.equals("9188")) {
                if (p_reqBat.reqHeader.commandCode.equals("918801")) {
                    transType = "01";
                } else if (p_reqBat.reqHeader.commandCode.equals("918802")) {
                    transType = "03";
                }
            }
            sendMap.put("transType", transType);

            sendMap.put("signType", "01");// 签名方式
            sendMap.put("merchantId", actItem.merchantId);
            sendMap.put("txnDate", Format.Date8Format.format(p_reqBat.getPayDateTime()));// 交易时间

            int maxBatch = getBankConfig().getValueAsInt("batSeqBeginWith");
            if (maxBatch == -1) {
                maxBatch = 1000;
            }
            StringBuilder sbLog = new StringBuilder();
            int countSeq = DirectHelper.countReqSeqIDMapping(p_reqBat.reqHeader.bankCode, p_reqBat.getPayDateOnly(), sbLog);
            if (countSeq < 0) {
                retAts.respCode = "0";
                retAts.respInfo = sbLog.toString();
                retAts.reqSeqID = p_reqBat.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = FailCode.E9981;
                retAts.writeRetToATS();
                return retAts;
            }
            maxBatch += countSeq;
            //maxBatch++;
            sbLog = new StringBuilder();
            boolean saved = DirectHelper.saveReqSeqIDMapping(p_reqBat.reqHeader.bankCode, p_reqBat.reqHeader.transType, p_reqBat.getPayDateOnly(), p_reqBat.reqBatchNO, maxBatch + "", sbLog);
            if (!saved) {
                retAts.respCode = "0";
                retAts.respInfo = sbLog.toString();
                retAts.reqSeqID = p_reqBat.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = FailCode.E9981;
                retAts.writeRetToATS();
                return retAts;
            }
			/*
			String dataDir = this.getDataFileDirectory(p_reqBat.getPayDateTime());
			File fileDir = new File(dataDir);
			if (fileDir.exists()) {
				File[] files = fileDir.listFiles();
				for (int i = 0; i < files.length; i++) {
					maxBatch++;
				}
			} else {
				fileDir.mkdirs();
			}
			File tmpFile = new File(fileDir,p_reqBat.reqBatchNO);
			tmpFile.createNewFile();
			FileHelper.writeFile(tmpFile, maxBatch+"", getCharset());
			*/

            sendMap.put("batchNo", String.format("%04d", maxBatch));
            sendMap.put("totalQty", p_reqBat.totalNum);
            sendMap.put("totalAmt", StringHelper.amountMultiply100(p_reqBat.totalAmt));
            //产生文件
            String fileContent = getFileContent(p_reqBat, actItem);// 文件
            WriteBankLogLn2("发送的批量文件内容" + fileContent);
            fileContent = new String(Base64.encodeBase64((DEHelper.compress(fileContent.getBytes(getCharset())))));
            sendMap.put("fileContent", fileContent);
            //有明细写数据库操作，需要再次校验超时时间
            StringBuilder sbLogChk = new StringBuilder();
            if (checkBankPayOverTime(p_reqBat.getPayDateTime(), "5", sbLogChk)) {
                String[] tmpStrRet = sendToBank(sendMap, actItem);// 发送银行
                if (tmpStrRet[0].length() == 0) {
                    Map<String, String> map = getRet(tmpStrRet[1]);
                    if (map != null && map.size() != 0) {
                        retAts.respCode = "0";
                        retAts.respInfo = map.get("respMsg");
                        retAts.reqSeqID = p_reqBat.reqBatchNO;
                        retAts.transState = map.get("respCode");
                        retAts.payInfoCode = map.get("respCode");
                    } else {
                        retAts.respCode = "-1";
                        retAts.respInfo = tmpStrRet[1].toString();
                    }
                } else if (tmpStrRet[0].equals(ConnState.FAIL)) {
                    retAts.respCode = "0";
                    retAts.respInfo = tmpStrRet[1];
                    retAts.reqSeqID = p_reqBat.reqBatchNO;
                    retAts.transState = PaymentState.FAIL_Batch;
                    retAts.payInfoCode = tmpStrRet[0];
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpStrRet[1];
                }
            } else {
                retAts.respCode = "0";
                retAts.respInfo = sbLogChk.toString();
                retAts.reqSeqID = p_reqBat.reqBatchNO;
                retAts.transState = PaymentState.FAIL_Batch;
                retAts.payInfoCode = FailCode.E9999;
            }
        } catch (Exception e) {
            retAts.respCode = "-1";
            retAts.respInfo = e.toString();
            e.printStackTrace();
        }
        if (retAts.respCode.equals("-1") && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
            retAts.reqSeqID = p_reqBat.reqBatchNO;
        }
        retAts.writeRetToATS();
        return retAts;
    }


    public RetAtsQryBatPayRec d_1998_QryBatPay(ReqQryBatPayRec p_req1998) throws Exception {
        return d_QryBatPayRec(p_req1998);
    }


    public RetAtsQryBatPayRec d_9198_QryBatPay(ReqQryBatPayRec p_req9198) throws Exception {
        return d_QryBatPayRec(p_req9198);
    }

    // 批量代收和批量代付状态查询
    public RetAtsQryBatPayRec d_QryBatPayRec(ReqQryBatPayRec p_reqQryBat) throws Exception {

        //HashMap<String, String> seqMap2 = DirectHelper.getSeqNum(p_reqQryBat.reqHeader.bankCode, p_reqQryBat.reqBatchNO);

        // 返回ATS的对象
        RetAtsQryBatPayRec retAts = new RetAtsQryBatPayRec(p_reqQryBat.reqHeader);
        retAts.respCode = "";
        ActSetItem actItem = getBankConfig().getActSetItem(p_reqQryBat.ownAct, "");
        if (actItem == null || !FileHelper.existFile(actItem.ownKeyStorePath)) {
            retAts.respCode = "-1";
            if (actItem == null) {
                retAts.respInfo = "未找到账号" + p_reqQryBat.ownAct + "的批量商户配置节点";
            } else {
                retAts.respInfo = "账号" + p_reqQryBat.ownAct + "的证书文件不存在";
            }
            retAts.reqSeqID = p_reqQryBat.reqBatchNO;
            //retAts.transState = PaymentState.FAIL_Batch;
            //retAts.payInfoCode = FailCode.E9981;
            retAts.writeBeforeDetail();
            retAts.writeAfterDetail();
            return retAts;
        }
        HashMap<String, String> sendMap = new HashMap<String, String>();
        sendMap.put("version", "1.0");
        sendMap.put("transCode", "batchQuery");
        String transType = "";
		/*01：代收自银行卡
02：代付到银行卡
03：代收自账户（暂不支持）
04：代付到账户
05：代发工资到账户
06：代发工资到银行卡
07：实时代付到银行卡
*/
        if (p_reqQryBat.reqHeader.transType.equals("1998")) {
            if (p_reqQryBat.reqHeader.commandCode.equals("198801")) {
                transType = "02";
            } else if (p_reqQryBat.reqHeader.commandCode.equals("198802")) {
                transType = "04";
            } else if (p_reqQryBat.reqHeader.commandCode.equals("198803")) {
                transType = "05";
            } else if (p_reqQryBat.reqHeader.commandCode.equals("198804")) {
                transType = "06";
            } else if (p_reqQryBat.reqHeader.commandCode.equals("198805")) {
                transType = "07";
            }
        } else if (p_reqQryBat.reqHeader.transType.equals("9198")) {
            if (p_reqQryBat.reqHeader.commandCode.equals("918801")) {
                transType = "01";
            } else if (p_reqQryBat.reqHeader.commandCode.equals("918802")) {
                transType = "03";
            }
        }
        sendMap.put("transType", transType);
        sendMap.put("signType", "01");
        sendMap.put("merchantId", actItem.merchantId);
        sendMap.put("txnDate", Format.Date8Format.format(p_reqQryBat.getBgnDateTime()));

        int maxBatch = 1;

        String toBankSeq = DirectHelper.getReqSeqIDMapping(p_reqQryBat.reqBatchNO);
        if (StringHelper.hasAnyChar(toBankSeq)) {
            maxBatch = Integer.parseInt(toBankSeq);
        } else {
            String dataDir = this.getDataFileDirectory(p_reqQryBat.getBgnDateTime());

            File fileDir = new File(dataDir);
            if (fileDir.exists()) {
                File tmpFile = new File(fileDir, p_reqQryBat.reqBatchNO);
                if (!tmpFile.exists()) {
                    if (canBeNotExist(p_reqQryBat, retAts, 45)) {
                        retAts.respCode = "0";
                        retAts.respInfo = "批次号" + p_reqQryBat.reqBatchNO + "没有批量代收付信息";
                        retAts.reqSeqID = p_reqQryBat.reqBatchNO;
                        retAts.transState = PaymentState.FAIL_Batch;
                        retAts.payInfoCode = FailCode.E9981;
                    }
                    retAts.writeBeforeDetail();
                    retAts.writeAfterDetail();
                    return retAts;
                }
                maxBatch = Integer.valueOf(FileHelper.readToString(tmpFile, getCharset()));
            } else {
                if (canBeNotExist(p_reqQryBat, retAts, 45)) {
                    retAts.respCode = "0";
                    retAts.respInfo = "批次号" + p_reqQryBat.reqBatchNO + "在" + p_reqQryBat.getBgnDateTime() + "没有批量代收付信息";
                    retAts.reqSeqID = p_reqQryBat.reqBatchNO;
                    retAts.transState = PaymentState.FAIL_Batch;
                    retAts.payInfoCode = FailCode.E9981;
                }
                retAts.writeBeforeDetail();
                retAts.writeAfterDetail();
                return retAts;
            }
        }

        sendMap.put("batchNo", String.format("%04d", maxBatch));
        // 发送数据
        try {
            String[] tmpStrRet = sendToBank(sendMap, actItem);// 发送银行
            if (tmpStrRet[0].length() == 0) {
                Map<String, String> map = getRet(tmpStrRet[1]);
                if (map != null && map.size() != 0) {
                    // 响应码相应
                    String retBatchNo = "";
                    if (map.containsKey("batchNo")) {
                        retBatchNo = map.get("batchNo");
                    }

                    String atsSeqID = DirectHelper.getAtsSeqIDMapping(Format.Date10Format.parse(p_reqQryBat.bgnDate),retBatchNo);
                    WriteBankLogLn2(retBatchNo + "在REQSEQIDMAPPING表中对应的ATS批次号为：" + atsSeqID);
                    if (p_reqQryBat.reqBatchNO.equals(atsSeqID)) {
                        if (map.get("respCode").equals("A0")) {
                            retAts.respCode = "0";
                            retAts.respInfo = map.get("respMsg");
                            retAts.transState = map.get("respCode");
                            retAts.reqSeqID = p_reqQryBat.reqBatchNO;
                            retAts.payInfoCode = retAts.transState;
                            retAts.writeBeforeDetail();
                            String fileContent = map.get("fileContent");
                            if (fileContent.length() > 0) {
                                BASE64Decoder base64Decoder = new BASE64Decoder();
                                byte[] bi = DEHelper.uncompress(base64Decoder.decodeBuffer(fileContent));
                                String resStr = new String(bi, getCharset());
                                this.WriteBankLogStep3(resStr);
                                String retDetails[] = resStr.split("\n");

                                HashMap<String, String> seqMap = DirectHelper.getSeqNum(p_reqQryBat.reqHeader.bankCode, p_reqQryBat.reqBatchNO);

                                for (String retDetail : retDetails) {
                                    RetAtsBatPayRecDetail tmpRetDetail = new RetAtsBatPayRecDetail();
                                    if (p_reqQryBat.reqHeader.transType.equals("1998")) {
                                        tmpRetDetail.payAct = actItem.merchantId;
                                        tmpRetDetail.recAct = retDetail.substring(493, 554).trim();
                                        tmpRetDetail.recName = retDetail.substring(342, 493).trim();
                                    } else if (p_reqQryBat.reqHeader.transType.equals("9198")) {
                                        tmpRetDetail.recAct = actItem.merchantId;
                                        tmpRetDetail.payAct = retDetail.substring(493, 554).trim();
                                        tmpRetDetail.payName = retDetail.substring(342, 493).trim();
                                    }
                                    tmpRetDetail.payAmount = StringHelper.amountDivide100(retDetail.substring(558, 576).trim());
                                    tmpRetDetail.curType = retDetail.substring(554, 558).trim();
                                    String usage = retDetail.substring(649, 651).trim().equals("99") ? "代发工资" : "普通代付";
                                    tmpRetDetail.usage = usage;
                                    tmpRetDetail.result = retDetail.substring(1222, 1230).trim();//retDetail.substring(1230,retDetail.length()).trim();
                                    tmpRetDetail.postScript = retDetail.substring(0, 64).trim();
                                    if (seqMap.containsKey(tmpRetDetail.postScript)) {
                                        tmpRetDetail.postScript = seqMap.get(tmpRetDetail.postScript);
                                    }
                                    tmpRetDetail.payInfoCode = retDetail.substring(1222, 1230).trim();
                                    tmpRetDetail.memo = retDetail.substring(1230, retDetail.length()).trim();
                                    retAts.writeRetDetail(tmpRetDetail);
                                }
                            }
                        } else {
                            boolean isContinue = true;
                            if ("A2".equalsIgnoreCase(map.get("respCode")) || map.get("respMsg").contains("批次不存在")) {
                                isContinue = canBeNotExist(p_reqQryBat, retAts, 45);
                            }
                            if (isContinue) {
                                retAts.respCode = "0";
                                retAts.transState = map.get("respCode") + "+" + map.get("respMsg");
                                retAts.payInfoCode = map.get("respCode");
                                retAts.respInfo = map.get("respMsg");
                                retAts.reqSeqID = p_reqQryBat.reqBatchNO;
                            }
                            retAts.writeBeforeDetail();
                        }
                    } else {
                        retAts.respCode = "-1";
                        retAts.reqSeqID = p_reqQryBat.reqBatchNO;
                        retAts.respInfo = "请求批次号[" + p_reqQryBat.reqBatchNO + "]与响应批次号[" + retBatchNo + "]对应的ATS批次号[" + atsSeqID + "]不符";
                        retAts.writeBeforeDetail();
                    }
                } else {
                    retAts.respCode = "-1";
                    retAts.respInfo = tmpStrRet[1].toString();
                }
            } else {
                retAts.respCode = "-1";
                retAts.respInfo = tmpStrRet[1];
            }
        } catch (Exception e) {
            retAts.respCode = "-1";
            retAts.respInfo = e.getMessage();
            e.printStackTrace();
        }
        if (retAts.respCode.equals("-1") && StringHelper.isNullOrEmpty(retAts.reqSeqID)) {
            retAts.reqSeqID = p_reqQryBat.reqBatchNO;
        }
        retAts.writeAfterDetail();
        return retAts;
    }

    /* 获取批量文件 */
    private String getFileContent(ReqBatPayRec p_reqBat, ActSetItem p_actItem) throws Exception {
        StringBuilder fileContent = new StringBuilder();
        HashMap<String, String> mapSeqNum = new HashMap<String, String>();
        while (p_reqBat.readRecord()) {
            //String orderNo = p_reqBat.readedDetail.askNumber; // 订单号
            //订单号orderNo,需要商户号+请求日期+业务号进行拼接,即商户号+年月日（系统日期）ATS传过来的PostScript（唯一业务号）
            String orderNo = p_actItem.merchantId + Format.Date8Format.format(p_reqBat.getPayDateOnly()) + p_reqBat.readedDetail.askNumber;
            mapSeqNum.put(p_reqBat.readedDetail.askNumber, orderNo);

            String bankCode = "", recBnk = "", descriptionName = "";//备注
            if (p_reqBat.reqHeader.transType.equals("1988")) {
                bankCode = p_reqBat.readedDetail.recBankCode;
                recBnk = p_reqBat.readedDetail.recBankLocation; // 开户行名称
                descriptionName = p_reqBat.readedDetail.recName;
            } else if (p_reqBat.reqHeader.transType.equals("9188")) {
                bankCode = p_reqBat.readedDetail.payBankCode;
                recBnk = p_reqBat.readedDetail.payBankLocation; // 开户行名称
                descriptionName = p_reqBat.readedDetail.payName;
            }
            String cnapsCode = p_reqBat.readedDetail.cnapsCode; // 开户行联行号
            String recCur = convertCurToBank(p_reqBat.readedDetail.recCur); // 交易币种
            String payAmount = StringHelper.amountMultiply100(p_reqBat.readedDetail.payAmount);// 交易金额
            String accType = ""; // 账户类型
            if (bankCode.equals("9021")) {
                accType = "3";//3：邦付宝账户
                bankCode = "";
            } else if (p_reqBat.readedDetail.isPrivate.equals("1")) {
                if (p_reqBat.readedDetail.cardType.equals("1")) {
                    accType = "1";
                } else {
                    accType = "0";
                }
            } else {
                accType = "2";
            }
            String certType = ""; // 证件类型
            String certNum = ""; // 证件号码
            String cardType = "";//卡种
            if (p_reqBat.readedDetail.cardType.equals("2")) {
                cardType = "01";
            } else if (p_reqBat.readedDetail.cardType.equals("3")) {
                cardType = "02";
            } else {
                cardType = "01";
            }
            if (p_reqBat.readedDetail.isPrivate.equals("1")) {
                certType = convertCertTypeToBank(p_reqBat.readedDetail.certType);
                certNum = p_reqBat.readedDetail.certNum;
            }
            String type = "";
            String name = "", act = "";
            if (p_reqBat.reqHeader.transType.equals("1988")) {
                type = "C";
                name = p_reqBat.readedDetail.recName; // 户名
                act = p_reqBat.readedDetail.recAct; // 账号
            } else if (p_reqBat.reqHeader.transType.equals("9188")) {
                type = "D";
                name = p_reqBat.readedDetail.payName; // 户名
                act = p_reqBat.readedDetail.payAct; // 账号
            }
            //资金用途
            String usage = getBankConfig().getMapValueByKey("useType" + p_reqBat.reqHeader.transType, p_reqBat.useType);

            String memo = p_reqBat.readedDetail.memo; //银行附言
            String cvv2 = p_reqBat.readedDetail.cvv2;
            String validDate = p_reqBat.readedDetail.expiredDate;
            String PaySpd = "";
            if (p_reqBat.paySpd != null)
                PaySpd = (p_reqBat.paySpd.equals("1") ? "1" : "2"); // 加急
            else {
                PaySpd = "2";
            }

            HashMap<String, String> trgHash = new HashMap<String, String>();
            trgHash.put("银行附言", memo);
            trgHash.put("备注", descriptionName);
            nodeAnalysis(p_reqBat.readedDetail.srcXElement, trgHash, getCharset());
            memo = trgHash.get("银行附言");
            descriptionName = trgHash.get("备注");

            fileContent.append(StringHelper.padRight(orderNo, 64, ' ') + " ")
                    .append(StringHelper.padRight(bankCode, 6, ' ') + " ")
                    .append(StringHelper.padRight(cnapsCode, 12, ' ') + " ")
                    .append(StringHelper.padRight(recBnk, 256, ' ') + " ")
                    .append(StringHelper.padRight(name, 150, ' ') + " ")
                    .append(StringHelper.padRight(act, 60, ' ') + " ")
                    .append(StringHelper.padRight(recCur, 3, ' ') + " ")
                    .append(StringHelper.padLeft(payAmount, 18, '0') + " ")
                    .append(StringHelper.padRight(accType, 1, ' ') + " ")
                    .append(StringHelper.padRight(certType, 2, ' ') + " ")
                    .append(StringHelper.padRight(certNum, 64, ' ') + " ")
                    .append(StringHelper.padRight(type, 1, ' ') + " ")
                    .append(StringHelper.padLeft(usage, 10, ' ') + " ")
                    .append(StringHelper.padRight(memo, 60, ' ') + " ")
                    .append(StringHelper.padRight(descriptionName, 256, ' ') + " ")
                    .append(StringHelper.padRight(cvv2, 6, ' ') + " ")
                    .append(StringHelper.padRight(validDate, 10, ' ') + " ")
                    .append(StringHelper.padRight(cardType, 2, ' ') + " ")
                    .append(StringHelper.padRight(PaySpd, 1, ' ') + " ")
                    .append(StringHelper.padRight("", 20, ' ') + " ")
                    .append(StringHelper.padRight("", 11, ' ') + " ")
                    .append(StringHelper.padRight("", 20, ' ') + " ")
                    .append(StringHelper.padRight("", 20, ' ') + " ")
                    .append(StringHelper.padRight("", 100, ' ') + " ")
                    .append(StringHelper.padRight("", 32, ' ') + " ")
                    .append(StringHelper.padRight("", 12, ' ') + " ")
                    .append(StringHelper.padRight("", 7, ' ') + " ")
                    .append(StringHelper.padRight("", 128, ' ') + "\r\n");
        }
        StringBuilder sbLog = new StringBuilder();
        boolean saved = DirectHelper.saveSeqNum(p_reqBat.reqHeader.bankCode, p_reqBat.reqBatchNO, mapSeqNum, sbLog);
        if (saved) {
            return fileContent.toString();
        } else {
            throw new Exception(sbLog.toString());
        }
    }
}
